package com.xja.food.controller;

import com.xja.food.entity.Users;
import com.xja.food.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @author 刘振升
 * @version 1.0
 * @date 2022/4/14 17:13
 * @description todo
 */
@Controller
@RequestMapping("user")
public class UsersController {
    Logger logger = LoggerFactory.getLogger(UsersController.class);
    @Reference(url = "dubbo://localhost:20882")
    private UserService userService;

    @RequestMapping("login")
    public String login(Users users, HttpSession Session) {
        logger.info("调用登录的方法");
        Users users1 = userService.login(users);
        if (users1.getUid() == 1) {
            Session.setAttribute("users1", users1);
            return "redirect:/food/foodlist";
        } else if (users1.getUid() > 1) {
            Session.setAttribute("users1", users1);
            return "redirect:/food/foodPuList";
        }
        return "redirect:/login.html";
    }
}
